package com.kfm.pm;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class CalendarExample {

    public static void main(String[] args) {
        Date date = new Date();
        date.setMonth(9);
        date.setDate(20);
        SimpleDateFormat sdf = new SimpleDateFormat();
        sdf.applyPattern("yyyy-MM-dd HH:mm:ss");
        System.out.println(sdf.format(date));
        Calendar calendar = Calendar.getInstance();
        //

        calendar.set(Calendar.YEAR, 2025);
        System.out.println(calendar.get(0));
        System.out.println(calendar.get(Calendar.YEAR));
        System.out.println(calendar.getActualMaximum(Calendar.YEAR));
        System.out.println(calendar.getActualMaximum(2));
        System.out.println(calendar.getActualMaximum(Calendar.DATE));

        calendar.set(2023, 8, 9);

        System.out.println(calendar.get(Calendar.MONTH));
        System.out.println(calendar.get(Calendar.YEAR));
        System.out.println(calendar.get(Calendar.DATE));
        // 1900 + year, month + 1, date
        Date d = new Date(2023 - 1900, 2, 19);
        // Date --> Calendar
        calendar.setTime(d);
        System.out.println(d);
        System.out.println(calendar.get(Calendar.YEAR));
        // 0 - 11
        System.out.println(calendar.get(Calendar.MONTH));
        // add(字段, 增加的值)
        calendar.add(Calendar.DATE, -20);
        System.out.println(calendar.get(Calendar.MONTH));
        System.out.println(calendar.getActualMaximum(Calendar.DATE));
        System.out.println(calendar.get(Calendar.DATE)); // 2022
        calendar.roll(Calendar.YEAR, 1);
        System.out.println(calendar.get(Calendar.MONTH));
        System.out.println(calendar.getActualMaximum(Calendar.DATE));
        System.out.println(calendar.get(Calendar.DATE)); // 2023


    }
}
